package com.hzqy.web.ac;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzqy.service.appointment.UserAppointmentServiceBean;
import com.hzqy.web.vo.WchatTvUserVo;
import com.hzqy.web.vo.wchat.UserAppointmentVo;

@Controller
@RequestMapping("/appointment")
public class UserAppointmentAction {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private UserAppointmentServiceBean userAppointmentServiceBean;

	/**
	 * 新增节目预约
	 * 
	 * @param userAppointmentVo
	 * @return
	 */
	@RequestMapping("/add_program_appointment")
	@ResponseBody
	public Object addProgramAppointment(HttpSession session, UserAppointmentVo userAppointmentVo) {
		WchatTvUserVo wchatTvUserVo = (WchatTvUserVo) session.getAttribute("WchatTvUserVo");
		userAppointmentVo.setF_uappointment_userid(wchatTvUserVo.getF_wtut_id());
		int flag=userAppointmentServiceBean.insertProgramAppointMent(userAppointmentVo);
		String mess;
		if(flag>=1){
			userAppointmentServiceBean.initUserAppointment();
			mess="预约成功";
		}else{
			mess="预约失败";
		}
		HashMap<String, String> hm=new HashMap<String, String>();
		hm.put("flag", flag+"");
		hm.put("mess", mess);
		return hm;
	}
	
	/**
	 * 删除节目预约
	 * 
	 * @param userAppointmentVo
	 * @return
	 */
	@RequestMapping("/delete_program_appointment")
	@ResponseBody
	public Object deleteProgramAppointment(HttpSession session, int f_uappointment_id) {
		int flag=userAppointmentServiceBean.deleteProgramAppointMent(f_uappointment_id);
		String mess;
		if(flag>=1){
			userAppointmentServiceBean.initUserAppointment();
			mess="删除成功";
		}else{
			mess="删除失败";
		}
		HashMap<String, String> hm=new HashMap<String, String>();
		hm.put("flag", flag+"");
		hm.put("mess", mess);
		return hm;
	}
	
	/**
	 * 修改节目预约
	 * 
	 * @param userAppointmentVo
	 * @return
	 */
	@RequestMapping("/update_program_appointment")
	@ResponseBody
	public Object updateProgramAppointment(HttpSession session, UserAppointmentVo userAppointmentVo) {
		int flag=userAppointmentServiceBean.updateProgramAppointMent(userAppointmentVo);
		String mess;
		if(flag>=1){
			mess="修改成功";
			userAppointmentServiceBean.initUserAppointment();
		}else{
			mess="修改失败";
		}
		HashMap<String, String> hm=new HashMap<String, String>();
		hm.put("flag", flag+"");
		hm.put("mess", mess);
		return hm;
	}
	
	/**
	 * 查询所有节目预约
	 * 
	 * @param userAppointmentVo
	 * @return
	 */
	@RequestMapping("/select_program_appointment_list")
	@ResponseBody
	public Object selectProgramAppointmentList(HttpSession session) {
		WchatTvUserVo wchatTvUserVo = (WchatTvUserVo) session.getAttribute("WchatTvUserVo");
		List<UserAppointmentVo> userAppointmentVoList=userAppointmentServiceBean.selectProgramAppointMentList(wchatTvUserVo.getF_wtut_id());
		return userAppointmentVoList;
	}
	
	/**
	 * 修改f_uappointment_status 是否生效
	 * 
	 * @param userAppointmentVo
	 * @return
	 */
	@RequestMapping("/update_f_uappointment_status")
	@ResponseBody
	public Object updateAppointmentStatus(HttpSession session,UserAppointmentVo userAppointmentVo) {
		int flag=userAppointmentServiceBean.updateAppointMentStatus(userAppointmentVo);
		if(flag>=1){
			userAppointmentServiceBean.initUserAppointment();
		}
		return flag;
	}
	
	/**
	 * 查询单个节目预约
	 * 
	 * @param userAppointmentVo
	 * @return
	 */
	@RequestMapping("/select_program_appointment")
	@ResponseBody
	public Object selectProgramAppointmen(HttpSession session, int f_uappointment_id) {
		UserAppointmentVo userAppointmentVo1=userAppointmentServiceBean.selectProgramAppointMent(f_uappointment_id);
		return userAppointmentVo1;
	}
}
